
#ifndef DISPLAYOBJECT_H
#define DISPLAYOBJECT_H

#include <GL\glew.h>

#include "Matrix4.h"

namespace Krengine
{
	class DisplayObject
	{
		public:
			explicit DisplayObject( float x = 0.0, float y = 0.0, float z = 0.0);
			~DisplayObject();

			/* translates the object's moving frame */
			void translate( float x, float y, float z );

			/* rotates the object's moving frame. Angle in radians */
			void rotate( float xAngle, float yAngle, float zAngle );

			/* changes the DO's shader to the requested type */
			bool setShader( int _shaderType );

			/* initializes DO's shader and generates and fills VBO's and a VAO to be used for rendering */
			bool prepareForRender( Matrix4 *projectionMatrix );

			/* deletes any used resources and buffers */
			void cleanupShader();

			/* draws the object on screen */
			void render();

			/* Outputs the objects coordinates */
			const std::string toString() const;

		protected:
			//TODO remove friend membership
			friend class Shader;

			enum
			{
				vertices,
				normal,
				color,
				index,
				numBuf
			};

			Shader *doShader;

			/* world coordinates */
			float xPos, yPos, zPos;
			/* local rotation in radians */
			float xRot, yRot, zRot;

			/* vertex-, color- and indexbuffer data*/
			GLfloat* vertBf;
			GLfloat* colorBf;
			GLuint*  indexBf;   //faces are drawn counter-clockwise
			/* vertex normals */
			GLfloat* normalBf;
			/* array with buffernames */
			GLuint bufferNm[numBuf];
			/* the length of bufferArrays */
			GLsizei bufferSize[numBuf];
			/* VertexArrayObject ID */
			GLuint vaoID;

			/* DO's used matrices */
			Matrix4 modelMatrix;
			Matrix4 normalMatrix;
			Matrix4 mvpMatrix;
			/* pointer to the environments projectionMatrix */
			Matrix4 *projMatrix;

			/* indicates if all the buffers and the shader are initialized */
			bool buffersInit;

		private:
			//TODO consider making public
			void updateMatrices();
	};
}
#endif
